package com.fuxiong.service.impl;

import com.fuxiong.dao.UserMapper;
import com.fuxiong.pojo.User;
import com.fuxiong.pojo.query.UserQuery;
import com.fuxiong.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> selectAllUser() {
        return userMapper.selectAllUser();
    }

    @Override
    public PageInfo<User> getUserByName(UserQuery userQuery) {
        //获取当前页码和显示数量
        PageHelper.startPage(userQuery.getPageNum(),userQuery.getPageSize());
        return new PageInfo<User>(userMapper.getUserByName(userQuery));
    }

    @Override
    public boolean deleteUserById(Integer id) {
        int i = userMapper.deleteUserById(id);
        if (i > 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public User queryUserById(Integer id) {
        return userMapper.queryUserById(id);
    }

    @Override
    public boolean updateUser(User user) {
        int i = userMapper.updateUser(user);
        if (i > 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean addUser(User user) {

        return userMapper.addUser(user) > 0 ? true : false;
    }
}
